import React, { Component } from 'react'
import MomentList from './MomentList'
import style from './Moments.module.scss'
import { connect } from "react-redux";
import { removeEmptyField } from '../compoent/emptyFild'
import moment from 'moment';
import {
    Form,
    Input,
    Button,
    DatePicker

} from 'antd';

class Moments extends Component {
    state = {
        data: [

        ],

    }

    onFinish = (values) => {
        const beginTime = values.beginTime
        values.beginTime = beginTime ? moment(beginTime[0]).format('YYYY-MM-DD') : ''
        values.endTime = beginTime ? moment(beginTime[1]).format('YYYY-MM-DD') : ''

        if (values) {
            //
            values.page = 1
            values.size = 5
            values.mId = values.mId ? values.mId.toString() : ''
            let newValues = removeEmptyField(values)
            this.props.moments(newValues)
        } else {
            this.props.moments()
        }

    };
    onFinishFailed = (errorInfo) => {

    };

    render() {
        const { RangePicker } = DatePicker;
        return (
            <div>
                <div className={style.top}>
                    <Form
                        style={{ marginTop: 20, marginLeft: 20 }}
                        name="basic"
                        layout='inline'
                        // wrapperCol={{ span: 6 }}
                        onFinish={this.onFinish}
                        autoComplete="off"

                    >
                        <Form.Item
                            style={{ width: 320 }}
                            label="用户名"
                            name="name"
                        >
                            <Input placeholder='请输入发单人查询' />
                        </Form.Item>
                        <Form.Item
                            style={{ width: 320 }}
                            label="ID"
                            name="mId"
                        >
                            <Input placeholder='请输入发单人查询' />
                        </Form.Item>

                        <Form.Item
                            style={{ marginTop: 0 }}
                            label="时间"
                            name="beginTime"
                        // rules={[{ message: 'Please input your username!' }]}
                        >
                            <RangePicker
                                ranges={{
                                    // Today: [moment(), moment()],
                                    '本周': [moment().startOf('week'), moment().endOf('week')],
                                    '本月': [moment().startOf('month'), moment().endOf('month')],
                                }} />


                        </Form.Item>

                            <Button type="primary" htmlType="submit">
                                查询
                            </Button>
                            <Button type="primary" htmlType='reset' style={{ marginLeft: 42 }}>
                                重置
                            </Button>
                    </Form>
                </div>
                <div className={style.middle}>
                    <MomentList />
                </div>
            </div>

        )
    }
}
const mapState = state => ({
    ...state.moments

});

const mapDispatch = dispatch => ({
    ...dispatch.moments
})

export default connect(mapState, mapDispatch)(Moments);